package com.cff.action;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.text.JTextComponent;

import com.cff.common.Constant;
import com.cff.util.EventUtil;
import com.cff.util.SignTools;

public class KeySetActionListener implements ActionListener {
	
	private String KeyType;
	
	public KeySetActionListener(String KeyType) {
		super();
		this.KeyType = KeyType;
	}


	@Override
	public void actionPerformed(ActionEvent e) {
		String keyDesc = "";
		if("PUBLICKEY".equals(KeyType)){
			keyDesc = "测试环境公钥";
		}
		if("PUBLICPROCKEY".equals(KeyType)){
			keyDesc = "生产环境公钥";		
		}
		if("PRIVATEKEY".equals(KeyType)){
			keyDesc = "测试环境私钥";
		}
		
		JFrame tmpFrame = new JFrame();
		tmpFrame.setBounds(300, 300, 450, 150);
		tmpFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		tmpFrame.setLayout(null);
		
		JLabel testPublicKeyLabel = new JLabel();
		testPublicKeyLabel.setBounds(20, 20, 150, 50);
		testPublicKeyLabel.setText(keyDesc+":");
		
		JTextField testPublicKeyText = new JTextField();
		testPublicKeyText.setBounds(130, 35, 250, 20);
		
		JButton okButton = new JButton("ok"); 
		okButton.setBounds(tmpFrame.getWidth()/2-50, tmpFrame.getHeight()-80, 50, 25);
		
		tmpFrame.add(testPublicKeyLabel);
		tmpFrame.add(testPublicKeyText);
		tmpFrame.add(okButton);
		GetKeyActionListener getKeyActionListener = new GetKeyActionListener(testPublicKeyText, tmpFrame, KeyType);
		EventUtil.putEvent(okButton,getKeyActionListener);
		tmpFrame.setVisible(true);
		
	}

}
